package com.manage.action;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.action.AbstractAction;
import com.manage.cache.SpCodeBanTimeManager;
import com.manage.model.SpCodeBanTime;
import com.util.Util;

public class SpCodeBanTimeAction extends AbstractAction {

	private static final long serialVersionUID = 1L;
	private Logger logger;
	private SpCodeBanTimeManager manager;
	private String        type;
	private List<SpCodeBanTime> list;
	private SpCodeBanTime model;
	
	private int spId;
	private String codeType;
	
	public SpCodeBanTimeAction()
	{
		logger = Logger.getLogger(this.getClass());
		manager = SpCodeBanTimeManager.getInstance();
	}
	
	public String execute()
	{
		return SUCCESS;
	}

	public String list()
	{
		list = manager.getSpCodeBanTimesBySpCodeId(model.getSpCodeId());
		return SUCCESS;
	}
	
	public String show()
	{
		if (model.getId() > 0)
		{
			model = manager.getSpCodeBanTime(model.getId());
			type = "update";
		}
		else
		{
			model.setId(-1);
			type = "insert";
		}

		return SUCCESS;
	}
	
	public String save()
	{
		if (type.equals("insert"))
		{
			model.setCreateDate(Util.dateToString(new Date()));
			model.setCreateUser(operator.getName());
		}
		model.setBanTimeProvince(model.getBanTimeProvince().replaceAll(" ", ""));
		manager.saveSpCodeBanTime(type, model);
		return SUCCESS;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<SpCodeBanTime> getList() {
		return list;
	}

	public void setList(List<SpCodeBanTime> list) {
		this.list = list;
	}

	public SpCodeBanTime getModel() {
		return model;
	}

	public void setModel(SpCodeBanTime model) {
		this.model = model;
	}

	public int getSpId() {
		return spId;
	}

	public void setSpId(int spId) {
		this.spId = spId;
	}

	public String getCodeType() {
		return codeType;
	}

	public void setCodeType(String codeType) {
		this.codeType = codeType;
	}
	
	
	
}
